//
//  CourseTextTableViewCell.m
//  Arts1
//
//  Created by 孤星晨宇 on 15/9/16.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "CourseTextTableViewCell.h"
#import "AllHeader.h"


@implementation CourseTextTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH - 20, 10)];
        _whiteView.backgroundColor = [UIColor whiteColor];
        
        _courseLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 40, 10)];
        _courseLabel.font = [UIFont systemFontOfSize:12];
        _courseLabel.textColor = kCustomColor(150, 150, 150, 1);
        _courseLabel.numberOfLines = 0;
        _courseLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_whiteView addSubview:_courseLabel];
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(10, self.bounds.size.height - 0.5, _whiteView.size.width, 0.5)];
        _lineView.backgroundColor = kCustomColor(150, 150, 150, 0.5);
        [_whiteView addSubview:_lineView];
        
        [self.contentView addSubview:_whiteView];
    }
    return self;
}

- (void)setStr:(NSString *)str{
    _str = str;
    _courseLabel.text = str;
    CGFloat height = [CourseTextTableViewCell heightForString:_str];
    _whiteView.frame = CGRectMake(10, 0, self.width - 20, height + 20);
    _courseLabel.frame = CGRectMake(10, 10, _whiteView.width - 20, height);
    
}


+ (CGFloat)heightForString:(NSString *)str{
    //  根据输入的字符串，计算label的高度
    
    //    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    //    CGRect rect = [str boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    
    CGRect rect = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 40, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName] context:nil ];
    return rect.size.height;
}

+ (CGFloat)heightForRow:(NSString *)str{
    return [CourseTextTableViewCell heightForString:str] + 20;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
